WEBVTT

00:01.470 --> 00:03.150
Hello and welcome back to the costs.

00:03.150 --> 00:11.160
So in the last sessions we already got in touch with String objects and now we we dig a bit deeper into

00:11.520 --> 00:13.130
the strings however.

00:13.440 --> 00:20.370
Also later in our real world projects then our focus is not on strings so we we keep it here as hard

00:20.370 --> 00:22.590
as possible.

00:22.590 --> 00:30.920
So at the end of the last session we transformed an integer five into a string by putting it into quotation

00:30.920 --> 00:32.140
marks.

00:32.180 --> 00:34.370
Let's repeat this again.

00:34.370 --> 00:41.090
So we are transforming into a five to a string and this completely changes the functionality of the

00:41.090 --> 00:41.660
object.

00:41.660 --> 00:44.360
So before five plus to give seven.

00:44.360 --> 00:54.740
And now if you execute this string five so represented by C plus two you get an error message.

00:54.740 --> 01:00.740
So it says it must be a string not an integer so it completely changes the functionality.

01:00.890 --> 01:02.900
But what other strings actually.

01:02.930 --> 01:08.040
Well strings up a sequence of Unicode characters inside a quotation mark.

01:08.660 --> 01:14.280
And this is treated like any other sequence like Lists Tuples which we see later.

01:14.280 --> 01:21.710
And yeah actually we can when we can put into a string many different characters like numbers letters

01:21.710 --> 01:27.170
special characters like question marks and exclamation marks and so on which you will see later.

01:27.200 --> 01:29.750
But before now let's start with.

01:29.750 --> 01:30.590
Just um.

01:30.590 --> 01:30.950
Yeah.

01:30.950 --> 01:38.240
Assigning or creating and string object Doc and assign the variable D.

01:38.870 --> 01:44.060
And also we create a string object cat and assign the right E.

01:45.110 --> 01:54.320
And no surprise if we print the types of DNA e both strings and if you tried to add both strings as

01:54.320 --> 01:59.410
before we tried to apply the plus operator let's see what we get here.

01:59.570 --> 02:05.350
So not Python does it just concatenate both strings so D plus E gets dark.

02:05.360 --> 02:11.590
Cat and if we might add E plus D we get cat dog.

02:11.600 --> 02:18.880
So it's just concatenate ing both strings and I yeah if you try to to a substrate you can.

02:18.890 --> 02:19.580
Error message.

02:19.580 --> 02:28.790
So minus the the minus operator is not the defined four strings and if you tried to multiply two strings

02:29.450 --> 02:31.970
we also get them error message.

02:32.600 --> 02:38.850
And if we tried to add uh let's say an integer to a string.

02:39.140 --> 02:40.050
That's awesome.

02:40.070 --> 02:47.960
Error message it doesn't work but if we transform our integer five into a string then of course we can

02:47.960 --> 02:55.810
add this string to another string like a cat or dog so we can talk five and it works.

02:55.820 --> 02:57.990
Also the other way around.

02:58.190 --> 03:06.680
So we get five dog and if you tried to multiply a string with an integer like five we get and string

03:06.680 --> 03:16.980
with a five times the copy of dog so we get talk talk talk talk dog so dark and times five is just concatenated

03:16.980 --> 03:22.580
ing five times talk and we can also do it the other way around and get the same result.

03:23.350 --> 03:26.330
So it doesn't matter if three times five four five times D.

03:26.620 --> 03:34.550
However if you transform the integer five to a string and try to multiply it with our string do you.

03:34.720 --> 03:40.560
Of course we get an error message and also we can concatenate many strings to one string.

03:40.560 --> 03:51.060
So for example we have the string I we the string half string 5 and the string docs and thought we get

03:51.060 --> 03:55.080
the statement I have five docs.

03:55.240 --> 03:59.010
So as you can see here we need the empty spaces here.

03:59.020 --> 04:07.750
If we forget these our sentence or our statement looks a bit a little bit unreadable.

04:07.750 --> 04:15.520
So Python can also handle spaces here and spaces can be part of a string so that s s quite comfortable

04:15.520 --> 04:16.930
here.

04:17.050 --> 04:20.740
What I would like to introduce here is string formatting.

04:20.890 --> 04:29.980
So we are assigning um the string docs to the variety of animal and the integer 6 to amount and then

04:29.980 --> 04:31.500
we print the statement.

04:32.020 --> 04:42.350
I have curly brackets curly brackets dot end of the quotes and then I apply it to the string the method

04:42.620 --> 04:49.580
format and insides of the brackets a format I'm I'm defining for which the curly brackets are place

04:49.580 --> 04:56.610
holders so undefined execute the cell here I get I have five docs.

04:56.810 --> 05:00.780
So what the method dot format actually does is that the.

05:00.810 --> 05:07.040
Yeah it fits the place holders um in the sequence as defined within the brackets here.

05:07.070 --> 05:13.760
So so the first curly bracket will be replaced by the amount and the second curly bracket will be replaced

05:13.760 --> 05:14.830
by animal.

05:15.050 --> 05:16.940
And uh yeah for example.

05:16.960 --> 05:19.460
So yesterday I had six docs.

05:19.520 --> 05:25.590
Now today I have not docs but cards and not six.

05:25.670 --> 05:34.830
But let's say eight I updated I got I have eight kids and this is quite helpful actually if you had

05:34.980 --> 05:41.610
your variables are changing many times and you want to automate your statement how many cards or talks

05:41.610 --> 05:43.610
you have currently.

05:43.620 --> 05:45.800
So that's that's quite helpful here.

05:45.950 --> 05:51.170
What you can also do you can delete a whole string by calling the DL function.

05:51.180 --> 06:03.950
So inside the brackets you put the object D so D stands for dark and if you deleted so if you then tried

06:03.950 --> 06:09.010
to print the so pretty is not defined here it says.

06:09.110 --> 06:19.250
So now we have to redefine DIA again in order D again OK dark before I mentioned that a string is a

06:19.250 --> 06:26.240
sequence of Unicode characters and um yeah you by calling the line function you can count the numbers

06:26.240 --> 06:36.180
of items in a string so with these we would expect three items d o a..

06:36.180 --> 06:37.110
All right.

06:37.110 --> 06:45.010
And we can also count the number of items or the number of characters and statement it's 40 and so let's

06:45.010 --> 06:47.640
go back to our statement.

06:48.430 --> 06:50.750
So our statement is I have five talks.

06:51.280 --> 06:55.000
So when we count we have to count actually all characters.

06:55.020 --> 06:56.660
So also the space character.

06:56.680 --> 07:08.080
So one two three four five six seven eight nine ten eleven twelve thirteen and also the DOT 14 characters.

07:08.080 --> 07:09.710
So that is correct here.

07:09.970 --> 07:16.540
And before we set different data types have different functionality so we could call the length length

07:16.540 --> 07:21.730
function on strings but we cannot call the length function on integers or floats.

07:21.730 --> 07:24.600
If you tried to do so you get an error message.

07:24.640 --> 07:32.450
So object type Integer has no length function or the length function is not defined and earlier we saw

07:32.450 --> 07:39.450
that integers and floats they have built in methods attributes and this holds also true for String object.

07:39.470 --> 07:47.270
So seeing objects also have predefined appeared in methods and attributes and one of this is uh the

07:47.360 --> 07:57.540
upper method and it's execute the upper method on our String objects statement and that s print statement.

08:02.090 --> 08:07.990
Now you can see all items all our characters are converted to uppercase.

08:08.120 --> 08:11.780
So what actually the upper method does that just.

08:12.010 --> 08:12.630
Yeah.

08:12.770 --> 08:20.970
It converts all characters to the uppercase and we can also call the opposite method.

08:21.010 --> 08:24.850
Dot lower if we do so we get.

08:24.850 --> 08:28.070
I have talked some here we can see all characters are.

08:28.160 --> 08:28.390
Yeah.

08:28.420 --> 08:30.140
Lowercase and s.

08:30.160 --> 08:32.280
Another method called capitalize.

08:32.290 --> 08:38.520
And if we call this method on statement we get I have talks but the.

08:38.620 --> 08:40.870
I hear you see is capitalized.

08:40.900 --> 08:47.690
So the first character in our string is capitalized with them the capitalized method and there are many

08:47.690 --> 08:51.300
more build and methods for String objects.

08:51.440 --> 08:59.550
And if you like you can look at the documentation or just press the dots tab to see what pace and office

08:59.550 --> 09:07.580
here and I can just try out what what happens if you call the the method then then the and attributes

09:07.580 --> 09:07.880
here

09:10.730 --> 09:18.650
but for now we are finished here with the strings and we head over to lists and s some function call

09:18.680 --> 09:24.980
list which tree app transforms a string object into a list so we can try.

09:25.130 --> 09:27.020
What happens here.

09:27.110 --> 09:34.150
So our statement is I have five docs and we transform it into a list and what we can see here.

09:34.160 --> 09:42.600
We have all single characters separated by a comma inside craft bracket brackets and this is called

09:42.600 --> 09:43.040
The List.

09:43.040 --> 09:50.270
So if you check the type type l This is a list and then the next lesson we will have a deeper look.

09:50.270 --> 09:51.960
To to the list object.

09:51.990 --> 09:54.100
But so for the time being.

09:54.140 --> 09:54.900
This is it.

09:54.920 --> 09:55.580
And the.

09:55.620 --> 09:55.880
Yeah.

09:55.880 --> 09:56.620
Hope you enjoyed it.

09:56.630 --> 09:58.010
And see you in the next session.
